package com.wanmait.hotelManage.webservlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.wanmait.hotelManage.dao.UserinfoDAO;
import com.wanmait.hotelManage.vo.City;
import com.wanmait.hotelManage.vo.Province;
import com.wanmait.hotelManage.vo.Userinfo;

/**
 * Servlet implementation class CityServerlet
 */
@WebServlet("/CityServerlet")
public class CityServerlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public CityServerlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String action=request.getParameter("action");
		if("province".equals(action)) {
			this.province(request, response);
		}
		else if("idBycity".equals(action)) {
			this.idBycity(request, response);
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void idBycity(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
	 int PrivaceId= Integer.parseInt(request.getParameter("id"));
	 List<City> findCityandPrivace = UserinfoDAO.getUserinfodao().FindCityandPrivace(PrivaceId);
	 request.setAttribute("findCityandPrivace",findCityandPrivace);
	 request.getRequestDispatcher("/FrontDesk/center/inc/city.jsp").forward(request, response);;
	}
	protected void province(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		Userinfo userinfo=(Userinfo)request.getSession().getAttribute("userinfo");
		ArrayList<Province> provinces=(ArrayList<Province>)UserinfoDAO.getUserinfodao().getProvince();
//		City city=(City)UserinfoDAO.getUserinfodao().FindCity();
		ArrayList<City> allCity=(ArrayList<City>)UserinfoDAO.getUserinfodao().FindCityandPrivace(userinfo.getCity().getProvince().getId());
		request.setAttribute("provinces", provinces);
		request.setAttribute("allCity",allCity);
		request.getRequestDispatcher("/FrontDesk/center/inc/privace.jsp").forward(request, response);
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
